<%@ page import="org.apache.commons.lang.StringUtils"%>
<%@ page language="java" import="java.util.*" %>
<%@ page language="java" import="java.io.*" %>
<%@ page language="java" import="com.tangdi.production.mpapp.utils.WebPayServletUtil"
	%>
<%@ page language="java" import="com.tangdi.production.mpapp.constants.Key"
	%>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%!public boolean sceneCheck(String scene) {
		if (StringUtils.isEmpty(scene)) {
			return false;
		} else if (Key.SCENE_ON_THE_SPOT.equals(scene)) {
			return true;
		} else if (Key.SCENE_REMOTE.equals(scene)) {
			return true;
		} else if (Key.SCENE_COMPANY.equals(scene)) {
			return true;
		} else if (Key.SCENE_CONSUMPTION.equals(scene)) {
			return true;
		} else if (Key.SCENE_CERTFICATION.equals(scene)) {
			return true;
		}
		return false;
	}%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setAttribute("on_back", "1");

	WebPayServletUtil payUtil = new WebPayServletUtil();
	
	//交易场景
	String scene = request.getParameter("scene");
	//公司收款不校验登录状态
	if(!Key.SCENE_COMPANY.equals(scene)){
		boolean ok = payUtil.validation(request, response);
		if (!ok) {
			payUtil.toLoginPage(request, response);
		}
	}
	
	//交易场景无效
	if (!sceneCheck(scene)) {
		payUtil.toIndexPage(request, response);
	}
	
	//订单类型 01收款 02商品
	String prdOrdType = request.getParameter("prdOrdType");
	if(StringUtils.isBlank(prdOrdType)){
		prdOrdType = "01";
	}
	
	//支付方式
	String payType = request.getParameter("payType");
	if(StringUtils.isBlank(payType)){
		payType = "";
	}
	//支付渠道
	String chl = request.getParameter("chl");
	if(StringUtils.isBlank(chl)){
		chl = "";
	}

	//结算类型T0T1
	String clearType = request.getParameter("clearType");
	if (!"00".equals(clearType)) {//不是T+0就当T+1处理
		clearType = "01";
	}
	
	//子业务类型
	String bizType = request.getParameter("bizType");
	if (bizType == null) {//不是T+0就当T+1处理
		bizType = "";
	}

	
	//潇客账号
	String SHOP_KE_TEL = request.getParameter("SHOP_KE_TEL");
	if (SHOP_KE_TEL == null) {
		SHOP_KE_TEL = "";
	}
	
	//充值金额
	String ordAmt = request.getParameter("ordAmt");
	if (ordAmt == null) {
		ordAmt = "";
	}
	//回调地址
	String backUrl = request.getParameter("backUrl");
	if (backUrl == null) {
		backUrl = "";
	}
	
	//第三方订单号
	String custOrderNo = request.getParameter("custOrderNo");
	if(custOrderNo == null){
		custOrderNo = "";
	}

	request.setAttribute("title", "快捷收款");
%>
<!DOCTYPE html>
<html lang="zh">
<base href="<%=basePath%>">
<head>
<title>快捷收款</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<meta name="description" content="Common form elements and layouts" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<%
	out.write("<script type=\"text/javascript\">");
	out.write("var scene='" + scene + "';");
	out.write("var clearType='" + clearType + "';");
	out.write("var bizType='" + bizType + "';");
	out.write("var ordAmt='" + ordAmt + "';");
	out.write("var backUrl='" + backUrl + "';");
	out.write("var custOrderNo='" + custOrderNo + "';");
	out.write("var prdOrdType='" + prdOrdType + "';");
	out.write("var payType='" + payType + "';");
	out.write("var chl='" + chl + "';");
	out.write("</script>");
%>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"
	charset="UTF-8"></script>

<script type="text/javascript" src="js/core-1.0.js" charset="UTF-8"></script>

<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="ace_v1.3/assets/css/bootstrap.css" />

<link rel="stylesheet" href="ace_v1.3/assets/css/chosen.css" />
<link rel="stylesheet" href="ace_v1.3/assets/css/font-awesome.css" />

<!-- text fonts -->
<link rel="stylesheet" href="ace_v1.3/assets/css/ace-fonts.css" />

<!-- ace styles -->
<link rel="stylesheet" href="ace_v1.3/assets/css/ace.css"
	class="ace-main-stylesheet" id="main-ace-style" />

<!--[if lte IE 9]>
			<link rel="stylesheet" href="ace_v1.3/assets/css/ace-part2.css" class="ace-main-stylesheet" />
		<![endif]-->

<!--[if lte IE 9]>
		  <link rel="stylesheet" href="ace_v1.3/assets/css/ace-ie.css" />
		<![endif]-->



<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->

<!--[if lte IE 8]>
		<script src="ace_v1.3/assets/js/html5shiv.js"></script>
		<script src="ace_v1.3/assets/js/respond.js"></script>
		<![endif]-->
<jsp:include page="../plug/head-include.jsp" />
<style type="text/css">
.fa-times-circle{
	color: #d68273;
}
.fa-check-circle{
	color: #d68273;
}
</style>

<script type="text/javascript">
	function createOrder($form){
		var pid = $("select[name='goodsName']").val();
		if(!pid){
			alert("请选择收款名称");
			return false;
		}
		$form = $($form);
		if(!TDValidateForm($form)){
			return false;
		}
		
		var bizType = $("input[name='bizType']").val();
		//远程支付每次提交都会创建订单并发送支付短信 ，实名认证也是用远程支付方式
		if(scene == "02" || scene == "05"){
			//远程支付进行手机号格式验证
			/* var phone = $("#BUYERTEL").val();
			if(!phone){
				alert("请输入接收短信的手机号!");
				return false;
			} */
			
			//var r = confirm("您正在创建一笔远程支付订单，创建成功后系统工会将支付短信发到持卡人手机进行支付，您确定要创建一笔新的收款订单吗？");
			var r = confirm("您正在创建一笔远程支付订单，系统将发送一条短信支付链接到付款人手机中！");
			if(r){
				return validateCallback($form,createSuccess);
			}
		}else{
			//var r = confirm("订单创建成功,您确定要进行付款操作吗?");
			//if(r){
				return validateCallback($form,createSuccess);
			//}
		}
		
		return false;
	}
	
	function createSuccess(json){
		//订单创建成功
		if(codeSuccess(json)){
			//进入订单查询页面
			var PRDORDNO = json["prdordNo"];
			if(!PRDORDNO){
				alert("订单创建异常，请重新下单！");
				return;
			}
			var payType = $("#payType").val();
			var chl = $("#payChannel").val();
			if(payType){//打开新窗口
				if(!chl){
					chl = "default";
				}
				var url = BASE_PATH + "paychl/pay_"+ payType +"_" + chl + ".jsp?prdOrdNo=" + PRDORDNO + "&scene=" + scene+ "&chl=" + chl;
				openUrl(url);
			}
			//openUrl(BASE_PATH + "kdpay/orderPay"+chl+".jsp?prdOrdNo=" + PRDORDNO + "&scene=" + scene+ "&payType=" + payType);
			//openUrl(BASE_PATH + "kdpay/order_show.jsp?prdOrdNo=" + PRDORDNO + "&payType=" + payType);
		}else{
			alert(json["RSPMSG"]);
			//未认证
			/* if(json["RSPCOD"] == "006699"){
				var r = confirm(json["RSPMSG"]);
				if(r){
					openUrl(BASE_PATH + "user/user_adv_certification.jsp");
				}
			}else{
				alert(json["RSPMSG"]);
			} */
		}
	}
</script>

</head>
<body class="no-skin">
	<!-- #section:basics/navbar.layout -->
	<jsp:include page="../plug/title.jsp" />

	<!-- /section:basics/navbar.layout -->
	<div class="main-container" id="main-container">

		<!-- #section:basics/sidebar -->
		<!-- /section:basics/sidebar -->
		<div class="main-content">
			<div class="main-content-inner">
				<!-- #section:basics/content.breadcrumbs -->
				<!-- /section:basics/content.breadcrumbs -->
				<div class="page-content">
					<!-- #section:settings.box -->
					<!-- <div class="page-header">
						<h1>
							Form Elements <small> <i
								class="ace-icon fa fa-angle-double-right"></i> Common form
								elements and layouts
							</small>
						</h1>
					</div>
					 -->
					 <div
						class="row-space clear-padding-left clear-padding-right clear-padding-top"></div>
					<div class="col-sm-8 col-xs-12 col-sm-offset-2 space-1"></div>
					<div class="row">
						<div class="col-xs-12">
							<!-- PAGE CONTENT BEGINS -->
							<form class="form-horizontal" method="post" action="PY0301.web"
								id="orderPayForm" role="form"
								onsubmit="return createOrder(this)">
								<input name="scene" value="<%=scene  %>" type="hidden" />
								<input name="clearType" value="<%=clearType  %>" type="hidden" />
								<input name="prdOrdType" value="<%=prdOrdType %>" type="hidden" />
								<input name="backUrl" value="<%=backUrl %>" type="hidden" />
								<input name="custOrderNo" value="<%=custOrderNo %>" type="hidden" />
								<input name="bizType" value="<%=bizType %>" type="hidden" />
								<!-- <div class="form-group">
									<div class="col-sm-8 col-xs-12 col-sm-offset-2">
										<span class="block input-icon input-icon-right">
											<input type="text" id="SHOP_KE" style="display: none;"
												class="form-control" />
										</span>
									</div>
								</div> -->
								<!-- <div class="form-group">
									<div class="col-sm-8 col-xs-12 col-sm-offset-2">
										<input type="text" id="BUYERTEL" style="display: none;"
											class="form-control" />
									</div>
								</div> -->

								<div class="form-group">
									<div class="col-sm-8 col-xs-12 col-sm-offset-2">
										<!-- <span class="input-group-addon">
											<i class="ace-icon fa fa-phone"></i>
										</span> -->
										<input type="text" name="prdordAmt" validate="true" value="<%=ordAmt %>"
											placeholder="请输入交易金额" class="form-control" />
									</div>
								</div>
								
								<div class="form-group">
									<div class="col-sm-8 col-xs-12 col-sm-offset-2">
										<!-- <span class="input-group-addon">
											<i class="ace-icon fa fa-phone"></i>
										</span> -->
										<input type="text" name="orderDesc" validate="true"
											placeholder="订单描述" class="form-control" />
									</div>
								</div>
								
								<div class="form-group">
									<div class="col-sm-8 col-xs-12 col-sm-offset-2">
										<!-- <span class="input-group-addon">
											<i class="ace-icon fa fa-phone"></i>
										</span> -->
										<select name="goodsName" class="chosen-select form-control">
											<option>商品收款</option>
											<option>货款收取</option>
											<option>旅游缴费</option>
											<option>其它收款</option>
										</select>
										<!-- <input type="text" name="PID" validate="true"
											placeholder="请输入商品名称及数量" class="form-control no-border" /> -->
									</div>
								</div>
								<div class="form-group">
									<div class="col-sm-8 col-xs-12 col-sm-offset-2">
										<!-- <span class="input-group-addon">
											<i class="ace-icon fa fa-phone"></i>
										</span> -->
										<select id="payType" name="payType" class="chosen-select form-control" defVal="<%=payType%>">
											<option value="04">微信支付</option>
											<option value="05">支付宝</option>
										</select>
										<!-- <input type="text" name="PID" validate="true"
											placeholder="请输入商品名称及数量" class="form-control no-border" /> -->
									</div>
								</div>
								<%-- <div class="form-group">
									<div class="col-sm-8 col-xs-12 col-sm-offset-2">
										<!-- <span class="input-group-addon">
											<i class="ace-icon fa fa-phone"></i>
										</span> -->
										<select id="payChannel" name="payChannel" class="chosen-select form-control" defVal="<%=chl%>">
											<option value="MinSheng">渠道三</option>
											<option value="MiShua">渠道二</option>
											<option value="KuBei">默认渠道</option>
										</select>
										<!-- <input type="text" name="PID" validate="true"
											placeholder="请输入商品名称及数量" class="form-control no-border" /> -->
									</div>
								</div> --%>
								<div class="row">
									<div class="col-sm-8 col-xs-12 col-sm-offset-2 space-1"></div>
								</div>
								<div class="row-space clear-padding-left clear-padding-right"></div>
								<div class="col-sm-8 col-xs-12 col-sm-offset-2 space-1"></div>
								
								<div class="col-sm-8 col-xs-12 col-sm-offset-2 pay_desc" style="display: none;">
						
								</div>
								<div class="col-sm-8 col-xs-12 col-sm-offset-2 space-1"></div>
					
								<div
									class="clearfix menu-btn-box col-sm-8 col-xs-12 col-sm-offset-2">
									<button class="btn btn-info btn-lg btn-block" type="submit" >
										<i class="ace-icon fa fa-check "></i>提交订单
									</button>
								</div>
							</form>
							<!-- /.col -->
						</div>
						
						
						<!-- /.row -->
					</div>
					

					<!-- /.page-header -->
				</div>
				<!-- /.page-content -->
			</div>
		</div>
		<!-- /.main-content -->

		<!-- /.main-container -->
	</div>
	<script type="text/javascript" src="js/core/selectOption.js" charset="UTF-8"></script>
	<script type="text/javascript">
		$(".chosen-select").initSelected();
	
		/* function inputIcon($input,success){
			if(!($input && $input.length > 0)){
				return;
			}
			var html = "<i class=\"ace-icon fa fa-check-circle\"></i>";
			$input = $($input);
			var $icon = $input.next(".fa");
			var $formGroup = $input.parents(".form-group");
			if($icon.length <= 0){
				$input.after(html);
				$icon = $input.next(".fa");
			}
			$formGroup.removeClass("has-success");
			$formGroup.removeClass("has-error");
			if(success == true){
				$formGroup.addClass("has-success");
				$icon.removeClass("fa-times-circle");
				$icon.addClass("fa-check-circle");
			}else{
				$icon.removeClass("fa-check-circle");
				$icon.addClass("fa-times-circle");
				$formGroup.addClass("has-error");
			}
		}
	
		if(scene == "02"){//远程支付需要的是手机号
			 var $input = $("#BUYERTEL");
			 $input.attr("placeholder","请输入付款人手机号");
			 $input.attr("name","BUYERTEL");
			 $input.attr("validate","true");
			 $input.attr("RegExp","/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/");
			 $input.attr("tips","手机号格式错误");
			 $input.show();
			 
			 var msg = "您正在发起远程收款操作，请填写付款人银行卡绑定的手机号并创建订单，系统会将支付短信发送到该手机号等待持卡人本人完成付款操作";
			 $(".pay_desc").html(msg).show();
				
		}else if(scene == "01"){//充值
			var $input = $("select[name='goodsName']");
			if(TRATYP == "00"){//199购买
				$input.html("<option selected='selected'>升级为VIP商户</option>");
				//$input.val("升级为VIP商户");
				$input.attr("readonly","readonly");
				
				var $input_AMT = $("input[name='AMOUNT']");
				$input_AMT.val("199.00");
				$input_AMT.attr("readonly","readonly");
				
				var msg = "您正在支付[￥199.00]元升级为VIP商户，交易费率T+1为0.6%；实时结算为0.7%。";
				$(".pay_desc").html(msg).show();
				
			}else if(TRATYP == "01"){//充值
				$input.html("<option selected='selected'>快捷收款</option>");
				//$input.val("快捷收款");
				$input.attr("readonly","readonly");
				
				var msg = "您正在进行快捷收款操作，充值成功后资金将存入您的个人账户。";
				$(".pay_desc").html(msg).show();
			}
		}else if(scene == "03"){//公司收款 - 远程收款 潇客充值
			var $input = $("select[name='goodsName']");
		
			$input.html("<option selected='selected'>业务收款</option>");
			//$input.val("快捷收款");
			$input.attr("readonly","readonly");
			
			var msg = "您正在进行付款给平台的操作，支付成功后资金将转入平台方。";
			$(".pay_desc").html(msg).show();
			 
			$("input[name='scene']").val("03");
			$("input[name='clearType']").val("01");
			$("input[name='TRATYP']").val("01");
			
			var comCustId = "16000000000001";
			//加入公司收款人Id
			$("input[name='scene']").before('<input name="custId" value="'+comCustId+'" type="hidden" />');
			
			$(".pay_desc").html(msg).show();
			 
		}else if(scene == "04"){//199购买
			var $input = $("select[name='goodsName']");
			$input.html("<option selected='selected'>升级为VIP商户</option>");
			//$input.val("升级为VIP商户");
			$input.attr("readonly","readonly");
			
			var $input_AMT = $("input[name='AMOUNT']");
			$input_AMT.val("199.00");
			$input_AMT.attr("readonly","readonly");
			
			$input_AMT.before("<input name='BIZTYPE' value='00' type='hidden' />");
			
			$("input[name='scene']").val("04");
			$("input[name='clearType']").val("01");
			$("input[name='TRATYP']").val("00");
			
			var msg = "支付[￥199.00]元升级为VIP商户，享有超低交易费率";
			$(".pay_desc").html(msg).show();
		}else if(scene == "05"){//实名认证
			var $input = $("#BUYERTEL");
			 $input.attr("placeholder","请输入本人信用卡绑定手机号");
			 $input.attr("name","BUYERTEL");
			 $input.attr("validate","true");
			 $input.attr("RegExp","/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/");
			 $input.attr("tips","手机号格式错误");
			 $input.show();
			 
			$input = $("select[name='goodsName']");
			$input.html("<option selected='selected'>实名认证</option>");
			//$input.val("实名认证");
			$input.attr("readonly","readonly");
			
			var $input_AMT = $("input[name='AMOUNT']");
			$input_AMT.val("1.00");
			$input_AMT.attr("readonly","readonly");
			
			$input_AMT.before("<input name='BIZTYPE' value='02' type='hidden' />");
			
			$("input[name='scene']").val("05");
			$("input[name='clearType']").val("01");
			$("input[name='TRATYP']").val("01");
			var msg = "请使用本人信用卡成功支付[￥1.00]元快速完成实名认证，认证成功后支付金额将退回到您的个人账户。";
			$(".pay_desc").html(msg).show();
		} */
	</script>
		<script type="text/javascript" src="ace_v1.3/assets/js/jquery.maskedinput.js" charset="UTF-8"></script>
	<script type="text/javascript" src="js/jquery.tips.js" charset="UTF-8"></script>
	
	<!-- basic scripts -->
</body>
</html>